package com.huaxin.hxcloud.activity;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.huaxin.common.media.view.PhotoAddView;
import com.huaxin.hxcloud.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 此类已遗弃
 * 使用dialog会导致小米魅族手机弹出层显示不出来 现在已经替换为 HxSationDialogFragment
 * Created by Administrator on 2016/12/8.
 */
@Deprecated
public class CommitDialog extends Dialog {

    @BindView(R.id.tv_title)
    TextView       tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.et_des)
    EditText       etDes;
    @BindView(R.id.photo_add_view)
    PhotoAddView   photoAdd;
    @BindView(R.id.rl_content)
    LinearLayout   rlContent;
    @BindView(R.id.bt_cancel)
    Button         btCancel;
    @BindView(R.id.bt_ok)
    Button         btOk;
    @BindView(R.id.rl_button)
    LinearLayout   rlButton;
    private OnClickListener mListener;
    private String[]        imgList, compress;
    private String title   = "添加备注";
    private int    maxSize = 4;
    private boolean isRecorderVideo;
    private boolean isVideo = false;
    private boolean isVisiablePhoto;

    public CommitDialog(Context context) {
        super(context, R.style.DialogTheme);
    }


    public CommitDialog(Context context, int themeResId) {
        super(context, themeResId);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_commit);
        ButterKnife.bind(this);
        setCancelable(false);
        initDate();
    }

    private void initDate() {
        photoAdd.setDatas(imgList, compress);
        photoAdd.setMaxSize(maxSize);
        photoAdd.isRecorderVideo(isRecorderVideo);
        tvTitle.setText(title);

    }

    public void setTitle(String title) {
        if (tvTitle != null) {
            tvTitle.setText(title);
        }
        this.title = title;
    }

    public void setImgList(String[] imgList, String[] compress) {
        this.imgList = imgList;
        this.compress = compress;
        if (photoAdd != null) {
            photoAdd.setDatas(imgList, compress);
        }
    }

    public String[] getImgs() {
        if (photoAdd == null) {
            return null;
        }
        return photoAdd.getCompressPaths();
    }

    public boolean isVideo() {
        if (photoAdd != null) {
            this.isVideo = photoAdd.isVideo();
        }
        return this.isVideo;
    }

    @Override
    public void setOnCancelListener(OnCancelListener listener) {
        super.setOnCancelListener(listener);
    }


    public void setOnCommitListener(OnClickListener listener) {
        mListener = listener;
    }

    @OnClick({R.id.bt_ok, R.id.bt_cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_ok:
                if (mListener != null) {
                    mListener.onClick(this, R.id.bt_ok);
                }
                break;
            case R.id.bt_cancel:
                if (mCancleLisetener !=null){
                    mCancleLisetener.cancle();
                }else{
                    cancel();
                }
                break;
            default:
                break;
        }
    }

    private CancleLisetener mCancleLisetener;

    public void setCancleLisetener(CancleLisetener cancleLisetener) {
        this.mCancleLisetener = cancleLisetener;
    }

    public interface CancleLisetener {
        void cancle();
    }

    public String getDes() {
        return etDes.getText().toString();
    }

    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
        if (photoAdd != null) {
            photoAdd.setMaxSize(maxSize);
        }
    }

    public void isRecorderVideo(boolean isRecorderVideo) {
        this.isRecorderVideo = isRecorderVideo;
        if (photoAdd != null) {
            photoAdd.isRecorderVideo(isRecorderVideo);
        }
    }

    public void setVisiablePhoto(boolean isVisiablePhoto) {
        this.isVisiablePhoto = isVisiablePhoto;
        if (photoAdd != null) {
            if (isVisiablePhoto) {
                photoAdd.setVisibility(View.VISIBLE);
            } else {
                photoAdd.setVisibility(View.GONE);
            }
        }
    }

    public void setTextBotton(String cancle, String confirm) {
        btCancel.setText(cancle);
        btOk.setText(confirm);
    }
}
